package com.youtills.resource;

/**
 * TODO - !!!doc me!!!
 *
 * @author ravi.chiluveru
 * @since 23.0 (10/16/14)
 */
public abstract class BaseAttribute<T, E extends BaseAttribute> implements Attribute<T>, MysqlAttribute {

    private final String name;
    private String mysqlColumnName;

    protected BaseAttribute(final String name) {
        this.name = name;
    }

    @Override
    public String getName() {
        return this.name;
    }

    public E setMysqlColumnName(String mysqlColumnName) {
        if(this.mysqlColumnName == null) {
            this.mysqlColumnName = mysqlColumnName;
        } else {
            throw new RuntimeException("Update not allowed");
        }

        return (E)this;
    }

    public String getMysqlColumnName() {
        return this.mysqlColumnName == null ? getName() : this.mysqlColumnName;
    }
}